from apps.common.base.dao import BaseDao
from apps.system.role.serializers import *
from apps.user.dao import UserDao

class RoleDao(BaseDao):
    MODEL_CLASS = Role
    SERI_CLASS = RoleBaseSerializer

    def create(self, data):
        if not data.get('parent'):
            if data.get('requestUserId'):
                user = UserDao().findOneByObjId(data.get('requestUserId'))
                data['parent'] = user.role.id
        return super().create(data)